package ar.edu.unq.leezsi.utils;

import java.util.ArrayList;
import java.util.List;

public class ClassUtils {
	public static <T> T newInstance(Class<T> clazz, Object[] params) {
		ClassWrapper<T> wrapper = new ClassWrapper<T>(clazz);
		return wrapper.newInstance(params);
	}

	public static Class<?>[] toClass(final Object... objects) {
		List<Class<?>> ret = new ArrayList<Class<?>>();
		for (Object object : objects) {
			ret.add(object.getClass());
		}
		return ret.toArray(new Class<?>[ret.size()]);
	}

	public static <T> ClassWrapper<T> wrapperFor(Object object) {
		return wrapperForName(object.getClass().getCanonicalName());
	}

	public static <T> ClassWrapper<T> wrapperForName(final String className) {
		return new ClassWrapper<T>(className);

	}

	public static <T> ClassWrapper<T> wrapperForName(String className,
			Runnable defaultAction) {
		try {
			return wrapperFor(className);
		} catch (Exception e) {
			defaultAction.run();
			return null;
		}
	}

	private ClassUtils() {
	}

}
